{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "8c4d576d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "import torch\n",
    "from torch.utils import data\n",
    "from d2l import torch as d2l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "580614c7",
   "metadata": {},
   "outputs": [],
   "source": [
    "def synthetic_data(w, b, num_examples):  #@save\n",
    "    \"\"\"生成 y = Xw + b + 噪声。\"\"\"\n",
    "    X = torch.normal(0, 1, (num_examples, len(w)))\n",
    "    y = torch.matmul(X, w) + b\n",
    "    y += torch.normal(0, 0.01, y.shape)\n",
    "    return X, y.reshape((-1, 1))\n",
    "\n",
    "true_w = torch.tensor([2, -3.4])\n",
    "true_b = 4.2\n",
    "features, labels = synthetic_data(true_w, true_b, 1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "7052c1f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<torch.utils.data.dataloader.DataLoader at 0x1f3af0f80f0>"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#数据加载过程\n",
    "def load_array(data_arrays, batch_size, is_train=True):  #@save\n",
    "    \"\"\"构造一个PyTorch数据迭代器。\"\"\"\n",
    "    dataset = data.TensorDataset(*data_arrays)\n",
    "    return data.DataLoader(dataset, batch_size, shuffle=is_train,drop_last=False)\n",
    "\n",
    "batch_size = 12\n",
    "data_iter = load_array((features, labels), batch_size)\n",
    "data_iter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "5542d847",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset = data.TensorDataset(*(features, labels))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "4c300fe4",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = data.DataLoader(dataset, 12, shuffle=True,drop_last=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "c0c3b4b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Sequential(\n",
       "  (0): Linear(in_features=2, out_features=1, bias=True)\n",
       ")"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# `nn` 是神经网络的缩写\n",
    "from torch import nn\n",
    "\n",
    "net = nn.Sequential(nn.Linear(2, 1,bias=True))\n",
    "net"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "099111ca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[-0.0547, -0.3646]]) tensor([-0.2179])\n",
      "tensor([[ 0.0024, -0.0150]]) tensor([0.])\n"
     ]
    }
   ],
   "source": [
    "print(net[0].weight.data,net[0].bias.data)\n",
    "net[0].weight.data.normal_(0, 0.01)\n",
    "net[0].bias.data.fill_(0)\n",
    "print(net[0].weight.data,net[0].bias.data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "490b1c0b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Sequential(\n",
       "  (0): Linear(in_features=2, out_features=1, bias=True)\n",
       ")"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "d62b8a57",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'torch.nn' has no attribute 'HuberLoss'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-111-660808d1e547>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m#loss = nn.MSELoss()\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mloss\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mHuberLoss\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m: module 'torch.nn' has no attribute 'HuberLoss'"
     ]
    }
   ],
   "source": [
    "#loss = nn.MSELoss()\n",
    "loss = torch.nn.HuberLoss()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "24a57043",
   "metadata": {},
   "outputs": [],
   "source": [
    "trainer = torch.optim.SGD(net.parameters(), lr=0.03)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "4db53be8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch 1, loss 0.000098\n",
      "epoch 2, loss 0.000099\n",
      "epoch 3, loss 0.000098\n",
      "epoch 4, loss 0.000098\n",
      "epoch 5, loss 0.000098\n",
      "epoch 6, loss 0.000098\n",
      "epoch 7, loss 0.000098\n",
      "epoch 8, loss 0.000098\n",
      "epoch 9, loss 0.000099\n",
      "epoch 10, loss 0.000099\n"
     ]
    }
   ],
   "source": [
    "num_epochs = 10\n",
    "for epoch in range(num_epochs):\n",
    "    for X, y in data_iter:\n",
    "        #print(X.size(),y.size())\n",
    "        l = loss(net(X) ,y)\n",
    "        trainer.zero_grad()\n",
    "        l.backward()\n",
    "        trainer.step()\n",
    "    l = loss(net(features), labels)\n",
    "    print(f'epoch {epoch + 1}, loss {l:f}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "8ed06f2a",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "w的估计误差： tensor([-2.7180e-05, -9.7251e-04])\n",
      "b的估计误差： tensor([0.0005])\n"
     ]
    }
   ],
   "source": [
    "w = net[0].weight.data\n",
    "print('w的估计误差：', true_w - w.reshape(true_w.shape))\n",
    "b = net[0].bias.data\n",
    "print('b的估计误差：', true_b - b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "41807c79",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[-0.0048, -0.0187]])"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net[0].weight.grad"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "98219cb9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'__name__': 'torch.nn',\n",
       " '__doc__': None,\n",
       " '__package__': 'torch.nn',\n",
       " '__loader__': <_frozen_importlib_external.SourceFileLoader at 0x1f3ac98a240>,\n",
       " '__spec__': ModuleSpec(name='torch.nn', loader=<_frozen_importlib_external.SourceFileLoader object at 0x000001F3AC98A240>, origin='C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\__init__.py', submodule_search_locations=['C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn']),\n",
       " '__path__': ['C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn'],\n",
       " '__file__': 'C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\__init__.py',\n",
       " '__cached__': 'C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\__pycache__\\\\__init__.cpython-36.pyc',\n",
       " '__builtins__': {'__name__': 'builtins',\n",
       "  '__doc__': \"Built-in functions, exceptions, and other objects.\\n\\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.\",\n",
       "  '__package__': '',\n",
       "  '__loader__': _frozen_importlib.BuiltinImporter,\n",
       "  '__spec__': ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>),\n",
       "  '__build_class__': <function __build_class__>,\n",
       "  '__import__': <function __import__>,\n",
       "  'abs': <function abs(x, /)>,\n",
       "  'all': <function all(iterable, /)>,\n",
       "  'any': <function any(iterable, /)>,\n",
       "  'ascii': <function ascii(obj, /)>,\n",
       "  'bin': <function bin(number, /)>,\n",
       "  'callable': <function callable(obj, /)>,\n",
       "  'chr': <function chr(i, /)>,\n",
       "  'compile': <function compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)>,\n",
       "  'delattr': <function delattr(obj, name, /)>,\n",
       "  'dir': <function dir>,\n",
       "  'divmod': <function divmod(x, y, /)>,\n",
       "  'eval': <function eval(source, globals=None, locals=None, /)>,\n",
       "  'exec': <function exec(source, globals=None, locals=None, /)>,\n",
       "  'format': <function format(value, format_spec='', /)>,\n",
       "  'getattr': <function getattr>,\n",
       "  'globals': <function globals()>,\n",
       "  'hasattr': <function hasattr(obj, name, /)>,\n",
       "  'hash': <function hash(obj, /)>,\n",
       "  'hex': <function hex(number, /)>,\n",
       "  'id': <function id(obj, /)>,\n",
       "  'input': <bound method Kernel.raw_input of <ipykernel.ipkernel.IPythonKernel object at 0x000001F38B6B85F8>>,\n",
       "  'isinstance': <function isinstance(obj, class_or_tuple, /)>,\n",
       "  'issubclass': <function issubclass(cls, class_or_tuple, /)>,\n",
       "  'iter': <function iter>,\n",
       "  'len': <function len(obj, /)>,\n",
       "  'locals': <function locals()>,\n",
       "  'max': <function max>,\n",
       "  'min': <function min>,\n",
       "  'next': <function next>,\n",
       "  'oct': <function oct(number, /)>,\n",
       "  'ord': <function ord(c, /)>,\n",
       "  'pow': <function pow(x, y, z=None, /)>,\n",
       "  'print': <function print>,\n",
       "  'repr': <function repr(obj, /)>,\n",
       "  'round': <function round>,\n",
       "  'setattr': <function setattr(obj, name, value, /)>,\n",
       "  'sorted': <function sorted(iterable, /, *, key=None, reverse=False)>,\n",
       "  'sum': <function sum(iterable, start=0, /)>,\n",
       "  'vars': <function vars>,\n",
       "  'None': None,\n",
       "  'Ellipsis': Ellipsis,\n",
       "  'NotImplemented': NotImplemented,\n",
       "  'False': False,\n",
       "  'True': True,\n",
       "  'bool': bool,\n",
       "  'memoryview': memoryview,\n",
       "  'bytearray': bytearray,\n",
       "  'bytes': bytes,\n",
       "  'classmethod': classmethod,\n",
       "  'complex': complex,\n",
       "  'dict': dict,\n",
       "  'enumerate': enumerate,\n",
       "  'filter': filter,\n",
       "  'float': float,\n",
       "  'frozenset': frozenset,\n",
       "  'property': property,\n",
       "  'int': int,\n",
       "  'list': list,\n",
       "  'map': map,\n",
       "  'object': object,\n",
       "  'range': range,\n",
       "  'reversed': reversed,\n",
       "  'set': set,\n",
       "  'slice': slice,\n",
       "  'staticmethod': staticmethod,\n",
       "  'str': str,\n",
       "  'super': super,\n",
       "  'tuple': tuple,\n",
       "  'type': type,\n",
       "  'zip': zip,\n",
       "  '__debug__': True,\n",
       "  'BaseException': BaseException,\n",
       "  'Exception': Exception,\n",
       "  'TypeError': TypeError,\n",
       "  'StopAsyncIteration': StopAsyncIteration,\n",
       "  'StopIteration': StopIteration,\n",
       "  'GeneratorExit': GeneratorExit,\n",
       "  'SystemExit': SystemExit,\n",
       "  'KeyboardInterrupt': KeyboardInterrupt,\n",
       "  'ImportError': ImportError,\n",
       "  'ModuleNotFoundError': ModuleNotFoundError,\n",
       "  'OSError': OSError,\n",
       "  'EnvironmentError': OSError,\n",
       "  'IOError': OSError,\n",
       "  'WindowsError': OSError,\n",
       "  'EOFError': EOFError,\n",
       "  'RuntimeError': RuntimeError,\n",
       "  'RecursionError': RecursionError,\n",
       "  'NotImplementedError': NotImplementedError,\n",
       "  'NameError': NameError,\n",
       "  'UnboundLocalError': UnboundLocalError,\n",
       "  'AttributeError': AttributeError,\n",
       "  'SyntaxError': SyntaxError,\n",
       "  'IndentationError': IndentationError,\n",
       "  'TabError': TabError,\n",
       "  'LookupError': LookupError,\n",
       "  'IndexError': IndexError,\n",
       "  'KeyError': KeyError,\n",
       "  'ValueError': ValueError,\n",
       "  'UnicodeError': UnicodeError,\n",
       "  'UnicodeEncodeError': UnicodeEncodeError,\n",
       "  'UnicodeDecodeError': UnicodeDecodeError,\n",
       "  'UnicodeTranslateError': UnicodeTranslateError,\n",
       "  'AssertionError': AssertionError,\n",
       "  'ArithmeticError': ArithmeticError,\n",
       "  'FloatingPointError': FloatingPointError,\n",
       "  'OverflowError': OverflowError,\n",
       "  'ZeroDivisionError': ZeroDivisionError,\n",
       "  'SystemError': SystemError,\n",
       "  'ReferenceError': ReferenceError,\n",
       "  'BufferError': BufferError,\n",
       "  'MemoryError': MemoryError,\n",
       "  'Warning': Warning,\n",
       "  'UserWarning': UserWarning,\n",
       "  'DeprecationWarning': DeprecationWarning,\n",
       "  'PendingDeprecationWarning': PendingDeprecationWarning,\n",
       "  'SyntaxWarning': SyntaxWarning,\n",
       "  'RuntimeWarning': RuntimeWarning,\n",
       "  'FutureWarning': FutureWarning,\n",
       "  'ImportWarning': ImportWarning,\n",
       "  'UnicodeWarning': UnicodeWarning,\n",
       "  'BytesWarning': BytesWarning,\n",
       "  'ResourceWarning': ResourceWarning,\n",
       "  'ConnectionError': ConnectionError,\n",
       "  'BlockingIOError': BlockingIOError,\n",
       "  'BrokenPipeError': BrokenPipeError,\n",
       "  'ChildProcessError': ChildProcessError,\n",
       "  'ConnectionAbortedError': ConnectionAbortedError,\n",
       "  'ConnectionRefusedError': ConnectionRefusedError,\n",
       "  'ConnectionResetError': ConnectionResetError,\n",
       "  'FileExistsError': FileExistsError,\n",
       "  'FileNotFoundError': FileNotFoundError,\n",
       "  'IsADirectoryError': IsADirectoryError,\n",
       "  'NotADirectoryError': NotADirectoryError,\n",
       "  'InterruptedError': InterruptedError,\n",
       "  'PermissionError': PermissionError,\n",
       "  'ProcessLookupError': ProcessLookupError,\n",
       "  'TimeoutError': TimeoutError,\n",
       "  'open': <function io.open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)>,\n",
       "  'copyright': Copyright (c) 2001-2021 Python Software Foundation.\n",
       "  All Rights Reserved.\n",
       "  \n",
       "  Copyright (c) 2000 BeOpen.com.\n",
       "  All Rights Reserved.\n",
       "  \n",
       "  Copyright (c) 1995-2001 Corporation for National Research Initiatives.\n",
       "  All Rights Reserved.\n",
       "  \n",
       "  Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.\n",
       "  All Rights Reserved.,\n",
       "  'credits':     Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands\n",
       "      for supporting Python development.  See www.python.org for more information.,\n",
       "  'license': See https://www.python.org/psf/license/,\n",
       "  'help': Type help() for interactive help, or help(object) for help about object.,\n",
       "  '__IPYTHON__': True,\n",
       "  'display': <function IPython.core.display.display(*objs, include=None, exclude=None, metadata=None, transient=None, display_id=None, **kwargs)>,\n",
       "  '__pybind11_internals_v3__': <capsule object NULL at 0x000001F38B781600>,\n",
       "  'get_ipython': <bound method InteractiveShell.get_ipython of <ipykernel.zmqshell.ZMQInteractiveShell object at 0x000001F38B6B4400>>},\n",
       " 'parameter': <module 'torch.nn.parameter' from 'C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\parameter.py'>,\n",
       " '_reduction': <module 'torch.nn._reduction' from 'C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\_reduction.py'>,\n",
       " 'grad': <module 'torch.nn.grad' from 'C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\grad.py'>,\n",
       " '_VF': <module 'torch.nn._VF'>,\n",
       " 'functional': <module 'torch.nn.functional' from 'C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\functional.py'>,\n",
       " 'init': <module 'torch.nn.init' from 'C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\init.py'>,\n",
       " 'utils': <module 'torch.nn.utils' from 'C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\utils\\\\__init__.py'>,\n",
       " 'modules': <module 'torch.nn.modules' from 'C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\modules\\\\__init__.py'>,\n",
       " 'Module': torch.nn.modules.module.Module,\n",
       " 'Identity': torch.nn.modules.linear.Identity,\n",
       " 'Linear': torch.nn.modules.linear.Linear,\n",
       " 'Conv1d': torch.nn.modules.conv.Conv1d,\n",
       " 'Conv2d': torch.nn.modules.conv.Conv2d,\n",
       " 'Conv3d': torch.nn.modules.conv.Conv3d,\n",
       " 'ConvTranspose1d': torch.nn.modules.conv.ConvTranspose1d,\n",
       " 'ConvTranspose2d': torch.nn.modules.conv.ConvTranspose2d,\n",
       " 'ConvTranspose3d': torch.nn.modules.conv.ConvTranspose3d,\n",
       " 'Threshold': torch.nn.modules.activation.Threshold,\n",
       " 'ReLU': torch.nn.modules.activation.ReLU,\n",
       " 'Hardtanh': torch.nn.modules.activation.Hardtanh,\n",
       " 'ReLU6': torch.nn.modules.activation.ReLU6,\n",
       " 'Sigmoid': torch.nn.modules.activation.Sigmoid,\n",
       " 'Tanh': torch.nn.modules.activation.Tanh,\n",
       " 'Softmax': torch.nn.modules.activation.Softmax,\n",
       " 'Softmax2d': torch.nn.modules.activation.Softmax2d,\n",
       " 'LogSoftmax': torch.nn.modules.activation.LogSoftmax,\n",
       " 'ELU': torch.nn.modules.activation.ELU,\n",
       " 'SELU': torch.nn.modules.activation.SELU,\n",
       " 'CELU': torch.nn.modules.activation.CELU,\n",
       " 'GLU': torch.nn.modules.activation.GLU,\n",
       " 'GELU': torch.nn.modules.activation.GELU,\n",
       " 'Hardshrink': torch.nn.modules.activation.Hardshrink,\n",
       " 'LeakyReLU': torch.nn.modules.activation.LeakyReLU,\n",
       " 'LogSigmoid': torch.nn.modules.activation.LogSigmoid,\n",
       " 'Softplus': torch.nn.modules.activation.Softplus,\n",
       " 'Softshrink': torch.nn.modules.activation.Softshrink,\n",
       " 'MultiheadAttention': torch.nn.modules.activation.MultiheadAttention,\n",
       " 'PReLU': torch.nn.modules.activation.PReLU,\n",
       " 'Softsign': torch.nn.modules.activation.Softsign,\n",
       " 'Softmin': torch.nn.modules.activation.Softmin,\n",
       " 'Tanhshrink': torch.nn.modules.activation.Tanhshrink,\n",
       " 'RReLU': torch.nn.modules.activation.RReLU,\n",
       " 'L1Loss': torch.nn.modules.loss.L1Loss,\n",
       " 'NLLLoss': torch.nn.modules.loss.NLLLoss,\n",
       " 'KLDivLoss': torch.nn.modules.loss.KLDivLoss,\n",
       " 'MSELoss': torch.nn.modules.loss.MSELoss,\n",
       " 'BCELoss': torch.nn.modules.loss.BCELoss,\n",
       " 'BCEWithLogitsLoss': torch.nn.modules.loss.BCEWithLogitsLoss,\n",
       " 'NLLLoss2d': torch.nn.modules.loss.NLLLoss2d,\n",
       " 'PoissonNLLLoss': torch.nn.modules.loss.PoissonNLLLoss,\n",
       " 'CosineEmbeddingLoss': torch.nn.modules.loss.CosineEmbeddingLoss,\n",
       " 'CTCLoss': torch.nn.modules.loss.CTCLoss,\n",
       " 'HingeEmbeddingLoss': torch.nn.modules.loss.HingeEmbeddingLoss,\n",
       " 'MarginRankingLoss': torch.nn.modules.loss.MarginRankingLoss,\n",
       " 'MultiLabelMarginLoss': torch.nn.modules.loss.MultiLabelMarginLoss,\n",
       " 'MultiLabelSoftMarginLoss': torch.nn.modules.loss.MultiLabelSoftMarginLoss,\n",
       " 'MultiMarginLoss': torch.nn.modules.loss.MultiMarginLoss,\n",
       " 'SmoothL1Loss': torch.nn.modules.loss.SmoothL1Loss,\n",
       " 'SoftMarginLoss': torch.nn.modules.loss.SoftMarginLoss,\n",
       " 'CrossEntropyLoss': torch.nn.modules.loss.CrossEntropyLoss,\n",
       " 'Container': torch.nn.modules.container.Container,\n",
       " 'Sequential': torch.nn.modules.container.Sequential,\n",
       " 'ModuleList': torch.nn.modules.container.ModuleList,\n",
       " 'ModuleDict': torch.nn.modules.container.ModuleDict,\n",
       " 'ParameterList': torch.nn.modules.container.ParameterList,\n",
       " 'ParameterDict': torch.nn.modules.container.ParameterDict,\n",
       " 'AvgPool1d': torch.nn.modules.pooling.AvgPool1d,\n",
       " 'AvgPool2d': torch.nn.modules.pooling.AvgPool2d,\n",
       " 'AvgPool3d': torch.nn.modules.pooling.AvgPool3d,\n",
       " 'MaxPool1d': torch.nn.modules.pooling.MaxPool1d,\n",
       " 'MaxPool2d': torch.nn.modules.pooling.MaxPool2d,\n",
       " 'MaxPool3d': torch.nn.modules.pooling.MaxPool3d,\n",
       " 'MaxUnpool1d': torch.nn.modules.pooling.MaxUnpool1d,\n",
       " 'MaxUnpool2d': torch.nn.modules.pooling.MaxUnpool2d,\n",
       " 'MaxUnpool3d': torch.nn.modules.pooling.MaxUnpool3d,\n",
       " 'FractionalMaxPool2d': torch.nn.modules.pooling.FractionalMaxPool2d,\n",
       " 'FractionalMaxPool3d': torch.nn.modules.pooling.FractionalMaxPool3d,\n",
       " 'LPPool1d': torch.nn.modules.pooling.LPPool1d,\n",
       " 'LPPool2d': torch.nn.modules.pooling.LPPool2d,\n",
       " 'LocalResponseNorm': torch.nn.modules.normalization.LocalResponseNorm,\n",
       " 'BatchNorm1d': torch.nn.modules.batchnorm.BatchNorm1d,\n",
       " 'BatchNorm2d': torch.nn.modules.batchnorm.BatchNorm2d,\n",
       " 'BatchNorm3d': torch.nn.modules.batchnorm.BatchNorm3d,\n",
       " 'InstanceNorm1d': torch.nn.modules.instancenorm.InstanceNorm1d,\n",
       " 'InstanceNorm2d': torch.nn.modules.instancenorm.InstanceNorm2d,\n",
       " 'InstanceNorm3d': torch.nn.modules.instancenorm.InstanceNorm3d,\n",
       " 'LayerNorm': torch.nn.modules.normalization.LayerNorm,\n",
       " 'GroupNorm': torch.nn.modules.normalization.GroupNorm,\n",
       " 'SyncBatchNorm': torch.nn.modules.batchnorm.SyncBatchNorm,\n",
       " 'Dropout': torch.nn.modules.dropout.Dropout,\n",
       " 'Dropout2d': torch.nn.modules.dropout.Dropout2d,\n",
       " 'Dropout3d': torch.nn.modules.dropout.Dropout3d,\n",
       " 'AlphaDropout': torch.nn.modules.dropout.AlphaDropout,\n",
       " 'FeatureAlphaDropout': torch.nn.modules.dropout.FeatureAlphaDropout,\n",
       " 'ReflectionPad1d': torch.nn.modules.padding.ReflectionPad1d,\n",
       " 'ReflectionPad2d': torch.nn.modules.padding.ReflectionPad2d,\n",
       " 'ReplicationPad2d': torch.nn.modules.padding.ReplicationPad2d,\n",
       " 'ReplicationPad1d': torch.nn.modules.padding.ReplicationPad1d,\n",
       " 'ReplicationPad3d': torch.nn.modules.padding.ReplicationPad3d,\n",
       " 'CrossMapLRN2d': torch.nn.modules.normalization.CrossMapLRN2d,\n",
       " 'Embedding': torch.nn.modules.sparse.Embedding,\n",
       " 'EmbeddingBag': torch.nn.modules.sparse.EmbeddingBag,\n",
       " 'RNNBase': torch.nn.modules.rnn.RNNBase,\n",
       " 'RNN': torch.nn.modules.rnn.RNN,\n",
       " 'LSTM': torch.nn.modules.rnn.LSTM,\n",
       " 'GRU': torch.nn.modules.rnn.GRU,\n",
       " 'RNNCellBase': torch.nn.modules.rnn.RNNCellBase,\n",
       " 'RNNCell': torch.nn.modules.rnn.RNNCell,\n",
       " 'LSTMCell': torch.nn.modules.rnn.LSTMCell,\n",
       " 'GRUCell': torch.nn.modules.rnn.GRUCell,\n",
       " 'PixelShuffle': torch.nn.modules.pixelshuffle.PixelShuffle,\n",
       " 'Upsample': torch.nn.modules.upsampling.Upsample,\n",
       " 'UpsamplingNearest2d': torch.nn.modules.upsampling.UpsamplingNearest2d,\n",
       " 'UpsamplingBilinear2d': torch.nn.modules.upsampling.UpsamplingBilinear2d,\n",
       " 'PairwiseDistance': torch.nn.modules.distance.PairwiseDistance,\n",
       " 'AdaptiveMaxPool1d': torch.nn.modules.pooling.AdaptiveMaxPool1d,\n",
       " 'AdaptiveMaxPool2d': torch.nn.modules.pooling.AdaptiveMaxPool2d,\n",
       " 'AdaptiveMaxPool3d': torch.nn.modules.pooling.AdaptiveMaxPool3d,\n",
       " 'AdaptiveAvgPool1d': torch.nn.modules.pooling.AdaptiveAvgPool1d,\n",
       " 'AdaptiveAvgPool2d': torch.nn.modules.pooling.AdaptiveAvgPool2d,\n",
       " 'AdaptiveAvgPool3d': torch.nn.modules.pooling.AdaptiveAvgPool3d,\n",
       " 'TripletMarginLoss': torch.nn.modules.loss.TripletMarginLoss,\n",
       " 'ZeroPad2d': torch.nn.modules.padding.ZeroPad2d,\n",
       " 'ConstantPad1d': torch.nn.modules.padding.ConstantPad1d,\n",
       " 'ConstantPad2d': torch.nn.modules.padding.ConstantPad2d,\n",
       " 'ConstantPad3d': torch.nn.modules.padding.ConstantPad3d,\n",
       " 'Bilinear': torch.nn.modules.linear.Bilinear,\n",
       " 'CosineSimilarity': torch.nn.modules.distance.CosineSimilarity,\n",
       " 'Unfold': torch.nn.modules.fold.Unfold,\n",
       " 'Fold': torch.nn.modules.fold.Fold,\n",
       " 'AdaptiveLogSoftmaxWithLoss': torch.nn.modules.adaptive.AdaptiveLogSoftmaxWithLoss,\n",
       " 'TransformerEncoder': torch.nn.modules.transformer.TransformerEncoder,\n",
       " 'TransformerDecoder': torch.nn.modules.transformer.TransformerDecoder,\n",
       " 'TransformerEncoderLayer': torch.nn.modules.transformer.TransformerEncoderLayer,\n",
       " 'TransformerDecoderLayer': torch.nn.modules.transformer.TransformerDecoderLayer,\n",
       " 'Transformer': torch.nn.modules.transformer.Transformer,\n",
       " 'Flatten': torch.nn.modules.flatten.Flatten,\n",
       " 'Parameter': torch.nn.parameter.Parameter,\n",
       " 'parallel': <module 'torch.nn.parallel' from 'C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\parallel\\\\__init__.py'>,\n",
       " 'DataParallel': torch.nn.parallel.data_parallel.DataParallel,\n",
       " 'intrinsic': <module 'torch.nn.intrinsic' from 'C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\intrinsic\\\\__init__.py'>,\n",
       " 'qat': <module 'torch.nn.qat' from 'C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\qat\\\\__init__.py'>,\n",
       " 'quantized': <module 'torch.nn.quantized' from 'C:\\\\ProgramData\\\\Miniconda3\\\\envs\\\\cyc-gan\\\\lib\\\\site-packages\\\\torch\\\\nn\\\\quantized\\\\__init__.py'>}"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "torch.nn.__dict__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "09e0d7d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.4.0'"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "torch.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dcff5082",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a1fb254",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
